package android.microblog.Adapter;

import java.util.List;

import android.content.Context;
import android.microblog.R;
import android.microblog.Data.UserInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemLongClickListener;

public class UserAdapter extends BaseAdapter {
	private Context context = null;
	private List<UserInfo> userList = null;

	public UserAdapter(Context c, List<UserInfo> list) {
		this.context = c;
		this.userList = list;
	}

	@Override
	public int getCount() {
		return userList.size();
	}

	@Override
	public Object getItem(int position) {
		return userList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context.getApplicationContext())
				.inflate(R.layout.item_user, null);

		ImageView iv = (ImageView) convertView.findViewById(R.id.iconImg);
		TextView tv = (TextView) convertView.findViewById(R.id.showName);
		UserInfo user = userList.get(position);
		try {
			iv.setImageDrawable(user.getUserIcon());
			tv.setText(user.getUserName());

		} catch (Exception e) {
			e.printStackTrace();
		}
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(context.getApplicationContext(),
						"" + v.toString(), Toast.LENGTH_SHORT).show();

			}
		});
		return convertView;
	}
}
